<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class Tags extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            'tag_name' => 'required|regex:/^[A-Za-z0-9\x{4e00}-\x{9fa5}]+$/u|between:2,20',
            'tag_sort' => 'required|integer',
            'tag_status' => 'required|in:1,2',
        ];
    }

    public function messages(): array
    {
        return [
            'tag_name.required' => '标签名称必须输入',
            'tag_name.regex' => '标签名称不能输入非法字符',
            'tag_name.between' => '标签名称长度只能是2至20个字符',

            'tag_sort.required' => '排序值必须输入',
            'tag_sort.integer' => '排序值只能是整数',

            'tag_status.required' => '状态值必须输入',
            'tag_status.in' => '状态值只能是1或者2',
        ];
    }
}
